package com.mifengkong.cygtools;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;

import com.mifengkong.cygtools.jjcard.CashByCreditCardBean;
import com.mifengkong.cygtools.jjcard.H5AutoFillDataBean;
import com.mifengkong.cygtools.jjcard.PhoneLoginModel;
import com.mifengkong.cygtools.jjcard.UserInfo;
import com.mifengkong.cygtools.model.AutoFillDataModel;
import com.mifengkong.cygtools.model.KaMaoModel;
import com.mifengkong.cygtools.model.SuDaiModel;
import com.mifengkong.frtools.http.request.callback.BaseImpl;
import com.mifengkong.frtools.http.request.callback.FRBaseObserver;
import com.mifengkong.frtools.util.FRLog;
import com.mifengkong.frtools.util.FRToast;

import java.util.List;

import io.reactivex.disposables.Disposable;

public class MainActivity extends Activity implements View.OnClickListener {

    private String mPath;

    private ImageView ivImage1, ivImage2, ivImage3, ivImage4;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        ivImage1 = findViewById(R.id.am_iv_image1);
        ivImage2 = findViewById(R.id.am_iv_image2);
        ivImage3 = findViewById(R.id.am_iv_image3);
        ivImage4 = findViewById(R.id.am_iv_image4);


        initListener();
//        mPath = Environment.getExternalStorageDirectory() + "/a.jpeg";
//        File file = new File(mPath);
//        if (file.exists()) {
//            FRLog.e("jiang", "图片存在");
//        }
    }

    private void initListener() {
        findViewById(R.id.am_btn_sudai).setOnClickListener(this);
        findViewById(R.id.am_btn_kamao).setOnClickListener(this);
        findViewById(R.id.am_btn_jijiancredit).setOnClickListener(this);
        findViewById(R.id.am_btn_jijianfetch).setOnClickListener(this);
        findViewById(R.id.am_btn_jiebaapi).setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.am_btn_sudai:
                FRToast.showToastSafe("你his电饭锅和ID");
//                requestSuDai();
//                FRImageLoad.loadImageTransForm("http://www.qqzhi.com/uploadpic/2015-01-22/073441407.jpg", ivImage1, 90);
                break;
            case R.id.am_btn_kamao:
//                FRImageLoad.loadImageGif("http://mifengkong.oss-cn-shenzhen.aliyuncs.com/kamao/qiandai.gif", ivImage2);
                requestKaMao();
                break;
            case R.id.am_btn_jijiancredit:
//                FRImageLoad.loadCircle("http://mifengkongdemo.oss-cn-shenzhen.aliyuncs.com/kamao/userlogo/_f175a1c391cb876f71f92ddb98458b46.jpg", ivImage3, R.mipmap.ic_launcher_round);
                updateAcator();
                break;
            case R.id.am_btn_jiebaapi:
                getdataForJieba();
                break;
            case R.id.am_btn_jijianfetch:
//                FRImageLoad.loadImage("", ivImage4, new RequestListener<Drawable>() {
//                    @Override
//                    public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
//                        FRLog.error("onLoadFailed---->" + e.getMessage());
//                        return false;
//                    }
//
//                    @Override
//                    public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
//                        FRLog.error("onResourceReady---->");
//                        return false;
//                    }
//                });
//                showImageDialog();
                startActivity(new Intent(MainActivity.this, TestActivity.class));
                break;
                default:

                    break;
        }
    }

    private void getdataForJieba() {

        AutoFillDataModel.getInstance().execute(new FRBaseObserver<List<H5AutoFillDataBean>>(new BaseImpl() {
            @Override
            public void addRxDestroy(Disposable disposable) {

            }

            @Override
            public Activity getActivity() {
                return MainActivity.this;
            }
        },"加载中") {
            @Override
            protected void onBaseNext(List<H5AutoFillDataBean> data) {
                FRLog.e("jiang", "onBaseNext:" + data.size());
            }
        });

    }

    private void showImageDialog() {
        DialogKaMaoActivity dialogKaMaoActivity = new DialogKaMaoActivity.Builder(this)
                .setImageUrl("http://mifengkong.oss-cn-shenzhen.aliyuncs.com/kamao/reward_advanced_2018.png")
                .create();
        dialogKaMaoActivity.show();
    }

    private void requestSuDai() {
        SuDaiModel.getInstance().execute(new FRBaseObserver<String>() {
            @Override
            protected void onBaseNext(String data) {
                FRLog.error("客服电话----->" + data);
            }
        });
    }

    private void requestKaMao() {
        KaMaoModel.getInstance().execute(new FRBaseObserver<CashByCreditCardBean>(new BaseImpl() {
            @Override
            public void addRxDestroy(Disposable disposable) {

            }

            @Override
            public Activity getActivity() {
                return MainActivity.this;
            }
        },"加载中....") {
            @Override
            protected void onBaseNext(CashByCreditCardBean data) {

            }
        });
    }

    private void updateAcator() {
//        UploadUserAvatorModel.getInstance().execute(new File(mPath), new FRBaseObserver<String>() {
//            @Override
//            protected void onBaseNext(String data) {
//
//            }
//        });

//        GetCardDataModel.getInstance().execute(new FRBaseObserver<CardMainBean>() {
//            @Override
//            protected void onBaseNext(CardMainBean data) {
//                FRLog.e("jiang",data.getCard_list().size()+"--");
//            }
//        });

        PhoneLoginModel.getInstance().execute(new FRBaseObserver<UserInfo>() {
            @Override
            protected void onBaseNext(UserInfo data) {
                FRLog.e("jiang", data.getPhone() + "--");
            }
        });

//        ReadAllMessageReadModel.getInstance().execute(new FRBaseObserver<String>() {
//            @Override
//            protected void onBaseNext(String data) {
//
//            }
//        });
    }
}
